package com.shiguiwu.springboot3.cart.controller;

import com.shiguiwu.springboot3.cart.properties.CommonProperties;
import com.shiguiwu.springboot3.cart.service.CommonService;
import com.shiguiwu.springboot3.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 普通controller
 * @author: stone
 * @date: Created by 2023/12/17 14:30
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springboot3.cart.controller
 */
@RestController
@RequestMapping("/common")
@Slf4j
public class CommonController {

    @Autowired
    private CommonProperties commonProperties;

    @Value("${cart.server}")
    private int serverPort;

    @Autowired
    private CommonService service;

    @GetMapping("/refresh")
    public R<CommonProperties> testPropertiesRefresh() {
        log.error("是否重新刷新对象 ===> {} ==> {}", commonProperties, serverPort);
        return R.ok(commonProperties);
    }

    /**
     * 测试单个对象返回
     * @return
     */
    @GetMapping("/test")
    public CommonProperties test() {
        log.error("是否重新刷新对象 ===> {} ==> {}", commonProperties, serverPort);
        return commonProperties;
    }

    public CommonController() {
        log.warn("创建对象===> {}", this);
    }
}
